<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class kewarganegaraan extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    function form_kewarganegaraan() {
        $this->template->load('halaman_v', 'admin/kewarganegaraan/tambah_kewarganegaraan_v');
    }

    function tambah() {
        if ($this->input->post('tambah') != NULL) {
            $data['idkewarganegaraan'] = $this->input->post('idkewarganegaraan');
            $data['kewarganegaraan'] = $this->input->post('kewarganegaraan');

            $this->load->model('umum_m');
            $this->umum_m->tambah('kewarganegaraan', $data);
            $this->tampil();
        }
    }

    function ubah($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_kewarganegaraan'] = $this->umum_m->ambil_data('kewarganegaraan', 'idkewarganegaraan = ' . $id)->row();
            $this->template->load('halaman_v', 'admin/kewarganegaraan/ubah_kewarganegaraan_v', $data);
        } else {
            redirect('admin/kewarganegaraan');
        }
    }

    function simpan_ubah() { //kalau data tidak diubah,maka....?
        if ($this->input->post() != null) {
            $kewarganegaraan['idkewarganegaraan'] = $this->input->post('idkewarganegaraan');
            $kewarganegaraan['kewarganegaraan'] = $this->input->post('kewarganegaraan');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('kewarganegaraan', $kewarganegaraan, 'idkewarganegaraan', $kewarganegaraan['idkewarganegaraan'])) {
                redirect('admin/kewarganegaraan/tampil');
            }
        }
    }

    function tampil() {
        $this->load->model('kewarganegaraan_m');
        $data['kewarganegaraan'] = $this->kewarganegaraan_m->ambil_data();
        $this->template->load('halaman_v', 'admin/kewarganegaraan/tampil_kewarganegaraan_v', $data);
    }
    
    function hapus($id = NULL){
        if($id != NULL){
            $this->load->model('umum_m');
            $status = $this->umum_m->cek_relasi_tabel('penduduk','idkewarganegaraan',$id);
            if($status == 0){
                $this->umum_m->hapus_data_tabel('kewarganegaraan',array('idkewarganegaraan'=>$id));
                $this->tampil();
            }
        }
    }
    

}

?>